home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / examples / instr.adb < prev    next >
Text File  |  1994-05-13  |  3KB  |  95 lines

  1. with Io; use Io;
  2. package body Instr is 
  3.  
  4.    procedure Set_Name (I : in out Instrument; S : String) is
  5.    begin 
  6.       for J in S'range loop 
  7.          I.Name (J) := S (J);
  8.          exit when J >= I.Name'Last;
  9.       end loop;
  10.    end Set_Name;
  11.  
  12.    procedure Display_Value (I : Instrument) is
  13.    begin
  14.       New_Line;
  15.       Put (I.Name);
  16.       Put (" : ");
  17.    end Display_Value;
  18.  
  19.  
  20.    procedure Display_Value (S : Speedometer) is
  21.    begin 
  22.       Display_Value (Instrument (S));
  23.       Put (S.Value);
  24.       Put (" Miles per Hour");
  25.    end Display_Value;
  26.  
  27.    procedure Display_Value (G : Gauge) is
  28.    begin
  29.       Display_Value (Instrument (G));
  30.       Put (G.Value);
  31.       Put (" %");
  32.    end Display_Value;
  33.    
  34.    procedure Display_Value (G : Graphic_Gauge) is
  35.       Lg : constant Integer := G.Size * G.Value / 100;
  36.       S1 : constant String (1 .. Lg) := (others => G.Fill);
  37.       S2 : constant String (Lg + 1 .. G.Size) := (others => G.Empty);      
  38.    begin
  39.       Display_Value (Instrument (G));
  40.       Put ('<');
  41.       Put (S1);
  42.       Put (S2);
  43.       Put ('>');
  44.    end Display_Value;
  45.  
  46.    procedure Display_Value (C : Clock) is 
  47.    begin 
  48.       Display_Value (Instrument (C));
  49.       Put (Character'Val (Character'Pos ('0') + C.Hours / 10));
  50.       Put (Character'Val (Character'Pos ('0') + C.Hours mod 10));
  51.       Put (":");
  52.       Put (Character'Val (Character'Pos ('0') + C.Minutes / 10));
  53.       Put (Character'Val (Character'Pos ('0') + C.Minutes mod 10));
  54.       Put (":");
  55.       Put (Character'Val (Character'Pos ('0') + C.Seconds / 10));
  56.       Put (Character'Val (Character'Pos ('0') + C.Seconds mod 10));
  57.    end Display_Value;
  58.       
  59.    procedure Increment (C : in out Clock; Inc : Integer := 1) is 
  60.       nInc : Integer;
  61.       
  62.    begin
  63.       C.Seconds := (C.Seconds + Inc) mod 60;
  64.       nInc := (C.Seconds + Inc) / 60;
  65.       C.Minutes := (C.Minutes + nInc) mod 60;
  66.       nInc := (C.Minutes + nInc) / 60;
  67.       C.Hours := (C.Hours + nInc) mod 24;
  68.    end Increment;
  69.  
  70.    procedure Init (C : in out Clock; 
  71.                    H : Twenty_Four := 0; 
  72.                    M, S : Sixty := 0) is
  73.    begin 
  74.       C.Seconds := S;
  75.       C.Minutes := M;
  76.       C.Hours := H;
  77.    end Init;
  78.    
  79.    procedure Display_Value (C : Chronometer) is
  80.    V : Integer;
  81.    begin 
  82.       Display_Value (Instrument (C));
  83.  
  84.       V :=  C.Seconds + C.Minutes * 60 + C.Hours   * 3600; 
  85.  
  86.       Put ("<<");
  87.       Put (Character'Val (Character'Pos ('0') + (V / 1000) mod 10));
  88.       Put (Character'Val (Character'Pos ('0') + (V / 100) mod 10));
  89.       Put (Character'Val (Character'Pos ('0') + (V / 10) mod 10));
  90.       Put (Character'Val (Character'Pos ('0') + V mod 10));
  91.       Put (">>");
  92.    end Display_Value;
  93.       
  94. end Instr;
  95.